package net.tycmc.cty.ctyms.timejob.iems.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.dao.ITransactionDAO;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.dbutil.global.GlobalDBVar;
import net.tycmc.cty.ctyms.timejob.common.DateList;
import net.tycmc.cty.ctyms.timejob.common.LogUtil;
import net.tycmc.cty.ctyms.timejob.common.SMSContentCfg;

public class AlarmFunctionDiagnosisDAO {
	private SMSInfoDAO smsInfoDAO;
	IBaseDAO baseDAO;
	private ITransactionDAO tranDAO;
	private MtnFaultDao malfunctionDiagnosisDAO;

	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}

	public ITransactionDAO getTranDAO() {
		return tranDAO;
	}

	public void setTranDAO(ITransactionDAO tranDAO) {
		this.tranDAO = tranDAO;
	}
	
	public MtnFaultDao getMalfunctionDiagnosisDAO() {
		return malfunctionDiagnosisDAO;
	}

	public void setMalfunctionDiagnosisDAO(
			MtnFaultDao malfunctionDiagnosisDAO) {
		this.malfunctionDiagnosisDAO = malfunctionDiagnosisDAO;
	}
	
	public SMSInfoDAO getSmsInfoDAO() {
		return smsInfoDAO;
	}

	public void setSmsInfoDAO(SMSInfoDAO smsInfoDAO) {
		this.smsInfoDAO = smsInfoDAO;
	}
	
	/**
	 * 获取最新报警
	 * @return
	 */
	public List<Map<String, Object>> getAlarmData(Map<String,String> map){
		/****2012-12-07****IEMS与TC合并****李晓凡******BEGIN***********/
//			String sql = "select ma.MsgAlm_RcvTime,ma.MsgAlm_ID,mac.MsgAlmC_ID,mac.MsgAlmC_IsAlarm,ma.MsgAlm_Vcl_ID,mac.MsgAlmC_SysA_ID," 
//					+"sa.SysA_ItemCN,'CTY_Egn_B' as DBName from CTY_Egn_B.dbo.Msg_Alarm as ma "
//					+"INNER JOIN CTY_Egn_B.dbo.Msg_Alarm_Content as mac on ma.MsgAlm_ID = mac.MsgAlmC_MsgAlm_ID "
//					+"INNER JOIN CTY_Egn_B.dbo.Sys_Alarm as sa on sa.SysA_ID=mac.MsgAlmC_SysA_ID and  (mac.MsgAlmC_SysA_ID  = 6 " +
//							"or mac.MsgAlmC_SysA_ID=7 or mac.MsgAlmC_SysA_ID=12)";
		String sql = "select alm.DBName,alm.MsgAlm_ID,alm.MsgAlm_MsgTime,alm.MsgAlm_RcvTime,alm.MsgAlm_Vcl_ID,alm.MsgAlmC_ID,alm.MsgAlmC_IsAlarm, "
			+"alm.MsgAlmC_SysA_ID,alm.SysA_ItemCN,alm.TableName from "
			+"(select ma.MsgAlm_MsgTime,ma.MsgAlm_RcvTime,ma.MsgAlm_ID,mac.MsgAlmC_ID,mac.MsgAlmC_IsAlarm,ma.MsgAlm_Vcl_ID,mac.MsgAlmC_SysA_ID, "
			+"sa.SysA_ItemCN,'B' as DBName,'Alarm' as TableName from CTY_Egn_B.dbo.Msg_Alarm as ma " 
			+"INNER JOIN CTY_Egn_B.dbo.Msg_Alarm_Content as mac on ma.MsgAlm_ID = mac.MsgAlmC_MsgAlm_ID " 
			+"INNER JOIN CTY_Egn_B.dbo.Sys_Alarm as sa on sa.SysA_ID=mac.MsgAlmC_SysA_ID and  (mac.MsgAlmC_SysA_ID  = 6 " 
			+"or mac.MsgAlmC_SysA_ID=7 or mac.MsgAlmC_SysA_ID=12) "
			+"UNION ALL select ma.MsgAlm_MsgTime,ma.MsgAlm_RcvTime,ma.MsgAlm_ID,mac.MsgAlmC_ID,mac.MsgAlmC_IsAlarm,ma.MsgAlm_Vcl_ID,mac.MsgAlmC_Alm_ID, "
			+"ai.Alm_ItemCN,'A' as DBName,'Alarm' as TableName from CTY_Egn_A.dbo.Msg_Alarm as ma "
			+"inner join CTY_Egn_A.dbo.Msg_Alarm_Content as mac on ma.MsgAlm_ID = mac.MsgAlmC_MsgAlm_ID "
			+"inner join CTY_Egn_A.dbo.Alarm_Item as ai on ai.Alm_ID=mac.MsgAlmC_Alm_ID and (mac.MsgAlmC_Alm_ID = 6 "
			+"or mac.MsgAlmC_Alm_ID=7 or mac.MsgAlmC_Alm_ID=12)) alm "
			+"inner join V_VehicleInfo v on v.VehicleID=alm.MsgAlm_Vcl_ID ";
		/****2012-12-07****IEMS与TC合并****李晓凡******END***********/
		if(map == null){
			String frontTimeStr = DateUtil.subMinute(10);
			sql+=" where alm.MsgAlm_RcvTime>='"+frontTimeStr+"'";
//			sql+=" where alm.MsgAlm_RcvTime>='2013-01-05 11:00:00'";
			LogUtil.info(this.getClass().getName(), "Begin -- 自动捕获自"+frontTimeStr+"到当前时刻发生的报警");
		}else if(map != null){
			String s_time = MapGetter.getString(map, "s_time");
			String e_time = MapGetter.getString(map, "e_time");
			sql += " where alm.MsgAlm_RcvTime>='"+s_time+"' and alm.MsgAlm_RcvTime<='"+e_time+"'";
			LogUtil.info(this.getClass().getName(), "Begin -- 手动捕获自"+s_time+"到"+e_time+"时刻发生的报警");
		}
		return baseDAO.execQuery(sql, new Object[]{});
	}

	/**
	 * 报警信息初始化
	 * @param map
	 */
	public boolean addAlarmState(Map<String, Object> map) {
		String DBName = MapGetter.getString(map, "DBName");
		String TableName = MapGetter.getString(map, "TableName");
		String MsgAlmC_ID = MapGetter.getString(map, "MsgAlmC_ID");
		String VclID = MapGetter.getString(map, "MsgAlm_Vcl_ID");
		String MsgID = MapGetter.getString(map, "MsgAlm_ID");
		String MsgTime = MapGetter.getString(map, "MsgAlm_MsgTime");
		String msgLo = MapGetter.getString(map, "MsgAlm_Lo");
		String msgLa = MapGetter.getString(map, "MsgAlm_La");
		
		boolean flag = false;
		//判断报警信息是否已经存在，若存在则return；反之，则继续运行
		boolean isExist = malfunctionDiagnosisDAO.isExist(2, DBName, TableName, MsgAlmC_ID);
		if(isExist){
			return flag;
		}
		
		//若报警不存在则插入到提示信息表中
		int ok = 0;
		try{
//			String sql = "insert into Msg_Fault_State(MsgFS_MsgF_ID,MsgFS_State,MsgFS_CreateTime,MsgFS_DBName,MsgFS_MsgFC_ID)values(?,?,?,?,?);";
//			String sql  = "insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_CreateTime)" 
//				+"values(?,?,?,?,2,1,?,?,GETDATE());";
//			ok = baseDAO.execUpdate(sql, new Object[]{VclID,MsgID,MsgAlmC_ID,MsgTime,DBName,TableName});
			/**2013.03.27 haoyang 修改 begin*/
			//原:MsgP_ID(自增),MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_CreateTime
			//增:MsgP_DetailMsg,MsgP_SecTypeId,MsgP_SecTypeName
			//注:MsgP_DetailMsg==MsgP_SecTypeName
			Map<String,Object> almMsg = getAlarmMsgByCID(DBName, MsgAlmC_ID);
			String sql  = "insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_CreateTime," +
					"MsgP_DetailMsg,MsgP_SecTypeId,MsgP_SecTypeName,MsgP_Lo,MsgP_La)" 
					+"values(?,?,?,?,2,1,?,?,GETDATE(),?,?,?,?,?);";
			ok = baseDAO.execUpdate(sql, new Object[]{VclID,MsgID,MsgAlmC_ID,MsgTime,DBName,TableName
					,MapGetter.getString(almMsg, "MsgP_SecTypeName"),MapGetter.getString(almMsg, "MsgP_SecTypeId"),MapGetter.getString(almMsg, "MsgP_SecTypeName")
					,msgLo,msgLa});
			/**end*/
			if(ok>0)flag = true;
		}catch(Exception e){
			e.printStackTrace();
			
		}
		LogUtil.info(this.getClass().getName(),"1.2.1JOB--向Msg_Prompt表中插入报警是否成功："+flag+";成功条数："+ok);
		return flag;
	}

	/**
	 * 发送报警短信
	 * @param map
	 */
	public boolean sendAlarmMsg(Map<String, Object> map,List<Map<String,Object>> userList) {
		String VehicleID = MapGetter.getString(map, "MsgAlm_Vcl_ID");
		String ItemID = MapGetter.getString(map, "MsgAlmC_SysA_ID");
		String MessageTime = MapGetter.getString(map, "MsgAlm_MsgTime");
		String DBName = MapGetter.getString(map, "DBName");
		String MsgID = MapGetter.getString(map, "MsgAlm_ID");
		String MsgCID = MapGetter.getString(map, "MsgAlmC_ID");
		String TableName = MapGetter.getString(map, "TableName");
		
		boolean flag = false;
		String isOccured_SQL;
		String dbname = malfunctionDiagnosisDAO.getDBName(DBName);
		if(DBName.equals("A")){
			isOccured_SQL = "select count(*) as cnt from SMS_SendRecord as sra "
				+"inner join "+dbname+".dbo.Msg_Alarm_Content as mac on sra.SSR_MsgCID=mac.MsgAlmC_ID " 
				+"inner join "+dbname+".dbo.Msg_Alarm as ma on mac.MsgAlmC_MsgAlm_ID = ma.MsgAlm_ID and ma.MsgAlm_Vcl_ID="+VehicleID 
				+"inner join "+dbname+".dbo.Alarm_Item as sa on sa.Alm_ID=mac.MsgAlmC_Alm_ID and sa.Alm_ID="+ItemID+"  where 1=1 ";
		}else if(DBName.equals("B")){
			isOccured_SQL = "select count(*) as cnt from SMS_SendRecord as sra " 
				+"inner join "+dbname+".dbo.Msg_Alarm_Content as mac on sra.SSR_MsgCID=mac.MsgAlmC_ID "
				+"inner join "+dbname+".dbo.Msg_Alarm as ma on mac.MsgAlmC_MsgAlm_ID = ma.MsgAlm_ID and ma.MsgAlm_Vcl_ID="+VehicleID
				+"inner join "+dbname+".dbo.Sys_Alarm as sa on sa.SysA_ID=mac.MsgAlmC_SysA_ID and sa.SysA_ID="+ItemID+"  where 1=1 ";
		}else{
			isOccured_SQL="";
			return flag;
		}
		
		//判断半小时内与本条设备ID、报警项目相同的报警信息是否发送过，若发送过则不发送，反之，发送。
		boolean isOccured = smsInfoDAO.assTimeIsOccured("4",isOccured_SQL);
		if(isOccured){
			return flag;
		}
		
		//过滤在非工作时间发送的重复信息
		isOccured = smsInfoDAO.nonWorkIsOccured("4","ma.MsgAlm_MsgTime", MessageTime,isOccured_SQL);
		if(isOccured){
			return flag;
		}
		
		//获得设备所属机构Code值
		Map<String,Object> codeMap = malfunctionDiagnosisDAO.getDBCode(VehicleID);
		//获取设备组织机构
		String DBCode =MapGetter.getString(codeMap, "DBCode");
		//获得设备号
		String VehicleNumber = MapGetter.getString(codeMap, "VehicleNumber");
		//时间
		String AlarmTime = MapGetter.getString(map, "MsgAlm_MsgTime");
		String time = DateList.getFormatDate(AlarmTime, 5);
			
		//报警项目
		String AlarmItem = MapGetter.getString(map, "SysA_ItemCN");
		
		String SMSContent = SMSContentCfg.SMSCCfgAlarm.replace("X_VclNum", VehicleNumber).replace("X_Date", time)
				.replace("X_Content", AlarmItem);
		
		//发送短信条件及sql语句
		List<String> sqlList = new ArrayList<String>();
		List<Object[]> paramList = new ArrayList<Object[]>();
		Map<String, Object> SMSMap = new HashMap<String, Object>();
		SMSMap.put("SMSType", "SMSAS_SMSAlm");
		SMSMap.put("SMSCfgType", 4);
		SMSMap.put("DBName", DBName);
		SMSMap.put("TabName", TableName);
		SMSMap.put("PromptType", 2);
		SMSMap.put("CreateType", 1);
		SMSMap.put("SMSContent", SMSContent);
		SMSMap.put("DBCode", DBCode);
		SMSMap.put("MsgID", MsgID);
		SMSMap.put("MsgCID", MsgCID);
		
		//发送短信 
		smsInfoDAO.promptSMSInfo(sqlList,paramList,SMSMap,userList);
		//添加 报警信息短信接收人sql,param
		malfunctionDiagnosisDAO.add_UpdateSMSRecUsersSql(sqlList, paramList, map, userList, "alarm");
		flag = this.tranDAO.batch(sqlList, paramList);
		LogUtil.info(this.getClass().getName(), "设备ID（"+MapGetter.getString(map, "MsgAlm_Vcl_ID")+"），报警项目（"+MapGetter.getString(map, "MsgAlmC_SysA_ID")+"）短信发送状态为："+flag);
		return flag;
	} 
	
	/**
	 * 短信发送内容
	 * @param userName
	 * @param map
	 * @return
	 */
	private String getSendContent(String userName, String VclNumber, Map<String, Object> map) {
		//时间
		String AlarmTime = MapGetter.getString(map, "MsgAlm_RcvTime");
		//报警项目
		String AlarmItem = MapGetter.getString(map, "SysA_ItemCN");
		
		return VclNumber+"在"+DateList.getFormatDate(AlarmTime, 5)+"检测到报警，内容："+AlarmItem;
	}
	
	/**
	 * 更新报警状态
	 * @param map
	 */
	public boolean updateAlarmState(Map<String, Object> map) {
		String DBName = MapGetter.getString(map, "DBName");
		String VclID = MapGetter.getString(map, "MsgAlm_Vcl_ID");
		String ItemID = MapGetter.getString(map, "MsgAlmC_SysA_ID");
		String MsgPRelsTime = MapGetter.getString(map, "MsgAlm_MsgTime");
		
		boolean flag = false;
		String sql;
		if(DBName.equals("A")){
			sql = "update Msg_Prompt set MsgP_State=3,MsgP_UpdateTime=GETDATE(),MsgP_ReleaseType=1,MsgP_ReleaseTime=? where MsgP_Type=2 and MsgP_DBName=? and MsgP_MsgCID in (" +
					"select MsgAlmC_ID from CTY_Egn_A.dbo.Msg_Alarm "+
					"inner join CTY_Egn_A.dbo.Msg_Alarm_Content on MsgAlm_ID=MsgAlmC_MsgAlm_ID and MsgAlm_Vcl_ID=? "+
					"inner join CTY_Egn_A.dbo.Alarm_Item on MsgAlmC_Alm_ID=Alm_ID and Alm_ID=?)";
		}else if(DBName.equals("B")){
			sql = "update Msg_Prompt set MsgP_State=3,MsgP_UpdateTime=GETDATE(),MsgP_ReleaseType=1,MsgP_ReleaseTime=? where MsgP_Type=2 and MsgP_DBName=? and MsgP_MsgCID in ( "
				+"select mac.MsgAlmC_ID from CTY_Egn_B.dbo.Msg_Alarm as ma  "
				+"inner join CTY_Egn_B.dbo.Msg_Alarm_Content as mac on ma.MsgAlm_ID=mac.MsgAlmC_MsgAlm_ID and mac.MsgAlmC_Vcl_ID=? "
				+"inner join CTY_Egn_B.dbo.Sys_Alarm as sa on sa.SysA_ID=mac.MsgAlmC_SysA_ID and sa.SysA_ID=?)";
		}else{
			sql = "";
			return flag;
		}
		
		int num = baseDAO.execUpdate(sql, new Object[]{MsgPRelsTime,DBName,VclID,ItemID});
		if(num > 0){
			flag = true;
		}
		LogUtil.info(this.getClass().getName(), "设备ID（"+MapGetter.getString(map, "MsgAlm_Vcl_ID")+"），报警项目（"+MapGetter.getString(map, "MsgAlmC_SysA_ID")+"）更新报警状态结果："+flag);
		return flag;
	}
	/**
	 * 获取 报警类型 及类型id
	 * @param DBName 
	 * @param AlmCID	:报警信息id
	 * @return
	 */
	public Map<String,Object> getAlarmMsgByCID(String DBName,String AlmCID){
		String sql = "";
		if("A".equals(DBName)){
			sql = "select Alm_ItemCN as msgp_sectypename,Alm_ID as msgp_sectypeid,msgAlmc.MsgAlmC_ID"
					+" from CTY_Egn_A.dbo.Msg_Alarm msgAlm"
					+" inner join CTY_Egn_A.dbo.Msg_Alarm_Content msgAlmc on MsgAlm_ID=MsgAlmC_MsgAlm_ID" 
					+" inner join CTY_Egn_A.dbo.Alarm_Item on Alm_ID=MsgAlmC_Alm_ID and (Alm_ID=6 or Alm_ID=7 or Alm_ID=12 or Alm_ID=11 or Alm_ID=13)" 
					+" where MsgAlmC_ID = ?";
		}else{
			sql = "select SysA_ItemCN as msgp_sectypename,SysA_ID as msgp_sectypeid,msgalmc.MsgAlmC_ID"
					+" from CTY_Egn_B.dbo.Msg_Alarm" 
					+" inner join CTY_Egn_B.dbo.Msg_Alarm_Content msgalmc on MsgAlm_ID=MsgAlmC_MsgAlm_ID" 
					+" inner join CTY_Egn_B.dbo.Sys_Alarm on SysA_ID=MsgAlmC_SysA_ID and (SysA_ID=6 or SysA_ID=7 or SysA_ID=12 or SysA_ID=11 or SysA_ID=13)" 
					+" where MsgAlmC_ID = ?";
		}
		return baseDAO.execQueryOne(sql, new Object[]{AlmCID});
	}
	
	public List<Map<String, Object>> getAlarmDataAB(Map<String, String> map) {
		List<Map<String,Object>> listA = null;
		List<Map<String,Object>> listB = null;
		try{
			//0.查询 A，B库报警统计 标记位
			String sql = "select fltMR_MsgF_ID as MsgAlm_ID,fltMR_DBName from fltMsgRecord where fltMR_TableName='Alarm' ";
			List<Map<String,Object>> listID = baseDAO.execQuery(sql, new Object[]{});
			//1.获取 故障信息
			listA = new ArrayList<Map<String,Object>>();
			listB = new ArrayList<Map<String,Object>>();
			String sql_A = "select alm.DBName,alm.MsgAlm_ID,alm.MsgAlm_MsgTime,alm.MsgAlm_RcvTime,alm.MsgAlm_Vcl_ID,alm.MsgAlmC_ID,alm.MsgAlmC_IsAlarm," 
						+" alm.MsgAlmC_SysA_ID,alm.SysA_ItemCN,alm.TableName,alm.MsgAlm_Lo,alm.MsgAlm_La from " 
						+" (select ma.MsgAlm_MsgTime,ma.MsgAlm_RcvTime,ma.MsgAlm_ID,mac.MsgAlmC_ID,mac.MsgAlmC_IsAlarm,ma.MsgAlm_Vcl_ID,mac.MsgAlmC_Alm_ID as MsgAlmC_SysA_ID,"
						+" ai.Alm_ItemCN as SysA_ItemCN,'A' as DBName,'Alarm' as TableName,ma.MsgAlm_Lo as MsgAlm_Lo,ma.MsgAlm_La as MsgAlm_La from CTY_Egn_A.dbo.Msg_Alarm as ma " 
						+" inner join CTY_Egn_A.dbo.Msg_Alarm_Content as mac on ma.MsgAlm_ID = mac.MsgAlmC_MsgAlm_ID	" 
						+" inner join CTY_Egn_A.dbo.Alarm_Item as ai on ai.Alm_ID=mac.MsgAlmC_Alm_ID and (mac.MsgAlmC_Alm_ID = 6	 " 
						+" or mac.MsgAlmC_Alm_ID=7 or mac.MsgAlmC_Alm_ID=12 or mac.MsgAlmC_Alm_ID=11 or mac.MsgAlmC_Alm_ID=13 )	"
						+" where ma.MsgAlm_ID > ? "
						+" ) alm " 
						+" inner join V_VehicleInfo v on v.VehicleID=alm.MsgAlm_Vcl_ID ";
			String sql_B ="select alm.DBName,alm.MsgAlm_ID,alm.MsgAlm_MsgTime,alm.MsgAlm_RcvTime,alm.MsgAlm_Vcl_ID,alm.MsgAlmC_ID,alm.MsgAlmC_IsAlarm, " 
						+" alm.MsgAlmC_SysA_ID,alm.SysA_ItemCN,alm.TableName,alm.MsgAlm_Lo,alm.MsgAlm_La from " 
						+" (select ma.MsgAlm_MsgTime,ma.MsgAlm_RcvTime,ma.MsgAlm_ID,mac.MsgAlmC_ID,mac.MsgAlmC_IsAlarm,ma.MsgAlm_Vcl_ID,mac.MsgAlmC_SysA_ID," 
						+" sa.SysA_ItemCN,'B' as DBName,'Alarm' as TableName,ma.MsgAlm_Lo as MsgAlm_Lo,ma.MsgAlm_La as MsgAlm_La from CTY_Egn_B.dbo.Msg_Alarm as ma	" 
						+" INNER JOIN CTY_Egn_B.dbo.Msg_Alarm_Content as mac on ma.MsgAlm_ID = mac.MsgAlmC_MsgAlm_ID " 
						+" INNER JOIN CTY_Egn_B.dbo.Sys_Alarm as sa on sa.SysA_ID=mac.MsgAlmC_SysA_ID and  (mac.MsgAlmC_SysA_ID  = 6 " 
						+" or mac.MsgAlmC_SysA_ID=7 or mac.MsgAlmC_SysA_ID=12 or mac.MsgAlmC_SysA_ID=11 or mac.MsgAlmC_SysA_ID=13) "
						+" where ma.MsgAlm_ID >  ? "
						+") alm " 
						+" inner join V_VehicleInfo v on v.VehicleID=alm.MsgAlm_Vcl_ID";	
			String aAlmid = "";
			String bAlmid = "";
			for(Map<String,Object> alm:listID){
				if(MapGetter.getString(alm, "fltMR_DBName").toUpperCase().equals("A")){
					aAlmid = MapGetter.getString(alm, "MsgAlm_ID");
				}else{
					bAlmid = MapGetter.getString(alm, "MsgAlm_ID");
				}
			}
			listA = baseDAO.execQuery(sql_A,
//					new Object[] {MapGetter.getString(listID.get(0), "MsgAlm_ID")});
					new Object[] {aAlmid});
			
			listB = baseDAO.execQuery(sql_B,
//					new Object[] {MapGetter.getString(listID.get(1), "MsgAlm_ID")});
					new Object[] {bAlmid});
			//2.获取最大MessageID
			String maxID_A = getMaxId(listA);
			String maxID_B = getMaxId(listB);
			//3.保存MessageID为新的标记位
			String update_A = "update fltMsgRecord set fltMR_MsgF_ID=?,fltMR_UpdateTime=getDate()" +
					" where fltMR_DBName='A' and fltMR_TableName='Alarm' ";
			String update_B = "update fltMsgRecord set fltMR_MsgF_ID=?,fltMR_UpdateTime=getDate()" +
					" where fltMR_DBName='B' and fltMR_TableName='Alarm' " ;
			if(listA.size()>0)
				baseDAO.execUpdate(update_A, new Object[]{maxID_A});
			if(listB.size()>0)	
				baseDAO.execUpdate(update_B, new Object[]{maxID_B});
			listA.addAll(listB);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return listA;
	}
	
	private String getMaxId(List<Map<String,Object>> almList){
		if(almList==null||almList.size()==0){
			return "";
		}
		int maxId=0;
		for (Map<String, Object> map : almList) {
			int msgID = Integer.parseInt(MapGetter.getString(map, "MsgAlm_ID"));
			if(maxId<msgID)
				maxId = msgID;
		}
		return ""+maxId;
	}
   /*向提示开关表中查询报警提示开关为关的设备信息
	 * wangkai-20141016
	 * 3.6.6新增
	 * vclpromptswitch:提示开关表
	 * VclPS_isOpen=0：开关状态为关
	 * VclPS_Type=2：提示开关类型为报警
	 */
	public List<String> getAlarmPromtPSwitch() {
		List<String> AlarmPromSwitch = new ArrayList<String>();

		String sql = "select VclPS_VclID from " +GlobalDBVar.getDBFullName_Conn("VclPromptSwitch","1",null)+
				" where VclPS_isOpen=0 and VclPS_Type=2 ";
		List<Map<String, Object>> list = baseDAO
				.execQuery(sql, new Object[] {});
		for (Map<String, Object> map : list) {
			AlarmPromSwitch.add(MapGetter.getString(map, "VclPS_VclID"));
		}
		return AlarmPromSwitch;
	}
}
